{extend name="public:layout" /}
{block name="title"}商品管理{/block}
{block name="head"}
<style>
    i{cursor:pointer}
</style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 商品列表</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <div class="pull-left">
                    <a class="btn btn-primary" href="{:url('add',['site_cid'=>$Request.param.site_cid])}">
                        <i class="fa fa-plus"></i>&nbsp;添加商品
                    </a>
                </div>
                <div class="pull-right">
                    <form class="form-inline" method="post" id="searchForm">
                        <input name="site_cid" type="hidden" />
                        <div class="form-group">
                            <select class="form-control" id="locatlSiteCid">
                                <option value="">所有分组</option>
                                {volist name="siteGroup" id="vo"}
                                <option value="{$vo.cid}" {eq name="query.site_cid" value="$vo['cid']"}selected{/eq}>{$vo._name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="form-group">
                            <input class="form-control" name="goods_name" value="{$query.goods_name}" type="text" placeholder="商品关键词">
                        </div>
                        <div class="form-group">
                        <button type="submit" class="btn btn-info">
                            <i class="fa fa-search"></i> 搜索
                        </button>
                        <a class="btn btn-white" href="{:url('index')}">
                            <i class="fa fa-trash"></i> 清空
                        </a>
                        </div>
                    </form>
                </div>
                <div class="clearfix"></div>
            </div>
            <ul class="nav nav-tabs" id="tab_search">
                <li {eq name="query.is_on_sale" value="1"}class="active"{/eq}><a href="{:url('index',['is_on_sale'=>1])}">出售中商品</a></li>
                <li {eq name="query.is_commend" value="1"}class="active"{/eq}><a href="{:url('index',['is_commend'=>1])}">推荐产品</a></li>
                <li {eq name="query.is_on_sale" value="0"}class="active"{/eq}><a href="{:url('index',['is_on_sale'=>0])}">已下架商品</a></li>
                <li {eq name="query.is_on_sale" value="10"}class="active"{/eq}><a href="{:url('index',['is_on_sale'=>10])}">违规下架商品</a></li>
            </ul>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="50">#</th>
                    <th>商品名称</th>
                    <th width="160">类目</th>
                    <th width="80">推荐</th>
                    <th width="120">状态</th>
                    <th width="120">操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list" id="vo"}
                <tr>
                    <td>{$vo.goods_id}</td>
                    <td>
                        <img src="{$vo.goods_thumb|default='/public/nopic.gif'}" class="pull-left" style="width:32px;height:32px;margin:4px;" />
                                {$vo.goods_name}
                    </td>
                    <td>{$siteGroup[$vo['site_cid']]['cat_name']}</td>
                    <td>
                        {eq name="vo.is_commend" value="1"}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_commend','0');" class="fa fa-check text-success"> </i>
                        {else/}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_commend','1');" class="fa fa-close text-warning"> </i>
                        {/eq}
                    </td>
                    <td>
                        {eq name="vo.is_on_sale" value="0"}已下架<a onclick="setStatus(this,'{$vo.goods_id}','is_on_sale','1');">上架</a>{/eq}
                        {eq name="vo.is_on_sale" value="1"}出售中<a onclick="setStatus(this,'{$vo.goods_id}','is_on_sale','0');">下架</a>{/eq}
                        {eq name="vo.is_on_sale" value="10"}
                        <a class="text-danger" data-toggle="popover" data-placement="left" title="违规下架原因" data-content="{$vo.sale_remark}">
                            违规下架
                        </a>
                        {/eq}
                    </td>
                    <td>
                        {neq name="vo.is_on_sale" value="10"}
                        <a href="{:url('copy',['goods_id'=>$vo['goods_id']])}">拷贝</a>
                        {/neq}
                        <a href="{:url('edit',['goods_id'=>$vo['goods_id']])}">编辑</a>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认删除吗？" data-url="{:url('del')}" data-params="goods_id={$vo.goods_id}">删除</a>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
            <div class="page-bar">{$list->render()}</div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('#locatlSiteCid').change(function () {
            var siteCid=$(this).val();
            $("input[name='site_cid']").val(siteCid);
            $('#searchForm').submit();
        });
        $('[data-toggle="popover"]').popover();
    });
    //切换状态
    function setStatus(obj,goodsId,field,status){
        var url="{:url('setStatus')}";
        var params = {goods_id:goodsId,field:field,status:status};
        getAjax(url, params, function (res) {
            rePage();
        });
    }
</script>
{/block}